//
//  MZ+AVF.swift
//  MZTool
//
//  Created by gby on 2023/3/28.
//

import UIKit
import AVFoundation

extension MZ{
    
    public static func videoFirstGen(_ path: URL) -> UIImage? {
        let asset = AVURLAsset.init(url: path)
        let assetImageGen = AVAssetImageGenerator(asset: asset)
        
        assetImageGen.appliesPreferredTrackTransform = true
        let time = CMTime(seconds: 0.0, preferredTimescale: 600)
        var actualTime:CMTime = .zero
        if let cgImage = try? assetImageGen.copyCGImage(at: time, actualTime: &actualTime) {
            let image = UIImage(cgImage: cgImage)
            return image
        }
        return nil
    }
    
}
